package com.csgc.camera.widget.dialog

import android.content.Context
import android.view.View

import com.csgc.camera.util.clickWithTrigger
import com.csgc.camera.widget.dialog.base.BottomDialog
import com.cysd.spsyxj.R

import com.hjq.shape.view.ShapeImageView

class PuzzleStyleDialog(val context: Context) {

    private lateinit var mDialog: BottomDialog
    private var currentStyle = 1
    private var style1: ShapeImageView?=null
    private var style2:ShapeImageView?=null
    private var style3:ShapeImageView?=null
    private var style4:ShapeImageView?=null
    var listener:OnPuzzleStyleChangeListener?=null

    init {
        initDialog()
    }

    private fun initDialog(){
        mDialog = BottomDialog(context).apply {
            setCustomView(R.layout.dialog_puzzle_style)
            findViewById<View>(R.id.iv_close_puzzle_style)?.clickWithTrigger {
                dismissDialog()
            }
            style1 = findViewById(R.id.siv_style_1)
            style2 = findViewById(R.id.siv_style_2)
            style3 = findViewById(R.id.siv_style_3)
            style4 = findViewById(R.id.siv_style_4)
            changeStyle()

            style1?.clickWithTrigger {
                currentStyle = 1
                changeStyle()
                listener?.onChange(currentStyle)
                dismissDialog()
            }
            style2?.clickWithTrigger {
                currentStyle = 2
                changeStyle()
                listener?.onChange(currentStyle)
                dismissDialog()
            }
            style3?.clickWithTrigger {
                currentStyle = 3
                changeStyle()
                listener?.onChange(currentStyle)
                dismissDialog()
            }
            style4?.clickWithTrigger {
                currentStyle = 4
                changeStyle()
                listener?.onChange(currentStyle)
                dismissDialog()
            }

        }
    }

    fun show(){
        mDialog.show()
    }
    fun dismissDialog(){
        mDialog.dismiss()
    }

    private fun changeStyle(){
        style1?.isSelected = currentStyle == 1
        style2?.isSelected = currentStyle == 2
        style3?.isSelected = currentStyle == 3
        style4?.isSelected = currentStyle == 4
    }

    interface OnPuzzleStyleChangeListener{
        fun onChange(style:Int)
    }
}